/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import service.GestionDocumentsWS;
import service.GestionDocumentsWS_Service;

/**
 *
 * @author laurent
 */
public class GestionDocumentClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
        GestionDocumentsWS_Service service = new GestionDocumentsWS_Service();
        GestionDocumentsWS port = service.getGestionDocumentsWSPort();
        
        File file = new File("./docReference.xml");
        FileInputStream fis = new FileInputStream(file);
        byte[] content = new byte[(int) file.length()];
//        fis.read(content);
//        System.out.println(port.depotDocument("docReference.xml", content));
//        
//        file = new File("./doc.xml");
//        fis = new FileInputStream(file);
//        content = new byte[(int) file.length()];
//        fis.read(content);
//        System.out.println(port.depotDocument("doc.xml", content));
//        
//        file = new File("./document.xml");
//        fis = new FileInputStream(file);
//        content = new byte[(int) file.length()];
//        fis.read(content);
//        System.out.println(port.depotDocument("document.xml", content));
//        
//        file = new File("/home/laurent/bibliotheque.xml");
//        fis = new FileInputStream(file);
//        content = new byte[(int) file.length()];
//        fis.read(content);
//        System.out.println(port.depotDocument("bibliotheque.xml", content));
        
        // Test de la fonction retourneDocument :
        service.Document doc = port.retourneDocument(2);
        if(doc.getNomFichier().equals("Fichier introuvable")) {
            System.out.println(doc.getNomFichier());
        } else {
            File f2 = new File("./Documents/" + doc.getNomFichier());
            FileOutputStream fos = new FileOutputStream(f2);
            fos.write(doc.getContent());
            fos.close();
        }
        
        // Test de la fonction Recherche :
        ArrayList<String> motscles = new ArrayList<String>();
        motscles.add("Bitch");
        motscles.add("Lol");
        System.out.println("Résultats de la recherche : " + port.rechercheDocuments(motscles));
        
        //Test de la methode genererPDF :
        file = new File("./bibliotheque.fo");
        fis = new FileInputStream(file);
        content = new byte[(int)file.length()];
        fis.read(content);
        doc = port.genererPDF(3, content);
        if(doc.getNomFichier().equals("Erreur")) {
            System.out.println("Erreur lors de la generation du pdf");
        } else {
            System.out.println("Fichier " + doc.getNomFichier() + " généré");
        File f2 = new File("./Documents/" + doc.getNomFichier());
        FileOutputStream fos = new FileOutputStream(f2);
        fos.write(doc.getContent());
        fos.close();
        }
    }
}
